package com.autoEcole.service;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import com.autoEcole.dao.ResultatDAO;
import com.autoEcole.exception.ApplicationException;
import com.autoEcole.exception.DAOException;
import com.autoEcole.model.Resultat;

public class ResultatService {
	
	private ResultatDAO resultatDAO;
	/**
	 * ResultatService
	 */
	private static ResultatService resultatService;
	
	/**
	 * Constructor
	 */
	private ResultatService() {
		super();
	}

	/**
	 * Returns the ResultatService instance (Design Pattern : Singleton)
	 * 
	 * @return ResultatService
	 */
	public static synchronized ResultatService getInstance() {
		if (resultatService == null)
			resultatService = new ResultatService();
		return resultatService;
	}

	public ResultatDAO getResultatDAO() {
		return resultatDAO;
	}

	public void setResultatDAO(ResultatDAO resultatDAO) {
		this.resultatDAO = resultatDAO;
	}

	public int create(Resultat resultat) throws ApplicationException {
		try {
			return resultatDAO.create(resultat);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * 
	 */
	public void update(Resultat resultat) throws ApplicationException {
		try {
			resultatDAO.update(resultat);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * retourne l'element si il existe ou null
	 */
	public Resultat findById(int id) throws ApplicationException {
		try {
			return resultatDAO.findById(id);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * @throws ParseException 
	 * 
	 */
	public List<Resultat> findAll() throws ApplicationException, ParseException {
		try {
			return resultatDAO.findAll();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
	
	/**
	 * 
	 */
	public Map<Integer , Resultat> findAllMap() throws ApplicationException {
		try {
			return resultatDAO.findAllMap();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}
	
	/**
	 * 
	 */	
	public void delete(int resultatId) throws ApplicationException {
		try {
			resultatDAO.delete(resultatId);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
}
